package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.GodBean;
import nero.yncc.com.createart.utils.ImageUtils;

/**
 * Created by nero on 17-6-21.
 */

public class AdapterIndexNewGod extends BaseAdapter {


    Context context;
    ArrayList<GodBean> arrayList;

    public AdapterIndexNewGod(Context context, ArrayList<GodBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            view = LinearLayout.inflate(context, R.layout.adapter_index_newgod, null);
            holder = new Holder(view);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        GodBean.Goods bean = arrayList.get(i).getGoods();
        holder.tv_title.setText(TextUtils.isEmpty(bean.getGoods_name()) ? context.getResources().getString(R.string.notitle) : bean.getGoods_name());
        holder.tv_content.setText(TextUtils.isEmpty(bean.getGoods_remark()) ? context.getResources().getString(R.string.noContent) : bean.getGoods_remark());
        holder.tv_money.setText("¥" + bean.getShop_price());
        ImageUtils.BindImage(context, holder.iv_image, bean.getOriginal_img(),1);
        return view;
    }

    class Holder {
        public Holder(View itemView) {
            iv_image = itemView.findViewById(R.id.iv_image);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_content = itemView.findViewById(R.id.tv_content);
            tv_money = itemView.findViewById(R.id.tv_money);
        }

        final ImageView iv_image;
        final TextView tv_title, tv_content, tv_money;
    }
}
